﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Algorithm.Easy_83_DeleteDuplicates
{
    public class ListNode
    {
        public int val;
        public ListNode next;
        public ListNode(int val = 0, ListNode next = null)
        {
            this.val = val;
            this.next = next;
        }
    }

    class MainProject
    {
        static void Main(string[] args)
        {
            //ListNode lis = new ListNode(1, new ListNode(1, new ListNode(2)));
            ListNode lis = new ListNode();
            //Console.WriteLine(IsPalindrome(0));
            ListNode listNode = DeleteDuplicates(lis);
            while (listNode.next!=null)
            {
                Console.WriteLine(listNode.val);
                listNode = listNode.next;
            }
            Console.ReadKey();
        }

        public static ListNode DeleteDuplicates(ListNode head)
        {
            if (head==null)
            {
                return head;
            }
            int value = head.val;
            ListNode listNode = head;
            while (listNode.next!=null)
            {
                if (listNode.next.val == value)
                {
                    listNode.next = listNode.next.next;
                }
                else
                {
                    value = listNode.next.val;
                    listNode = listNode.next;
                }
            }
            return head;
        }
    }
}
